// // Copyright (c) 2009 All Right Reserved // // vl // // 2009-01-01 // Contains ... namespace LargoCommon.Music { using System; using System.Collections; using System.Collections.ObjectModel; using System.Diagnostics.Contracts; using System.Globalization; using System.Linq; using System.Text; using System.Xml.Linq; using System.Xml.Serialization; using Abstract; using LargoCommon.Interfaces; //// Do not remove! (see FOR ALL call) /// Harmonic structure. /// Properties: continuity, impulse, measure of dissonance, genus /// in modality: continuity, impulse, potential, tonicity /// to tonic: continuity, impulse ... [Serializable] [XmlRoot] public sealed class HarmonicStructure : BinarySchema, IHarmonic, IModalStruct { #region Fields /// Root and principal element. private short rootElement, principalElement; /// String of musical symbols. private string toneSchema; /// /// The shortcut /// private string shortcut; #endregion #region Constructors /// Initializes a new instance of the HarmonicStructure class. Serializable. public HarmonicStructure() { this.rootElement = -1; this.principalElement = -1; this.toneSchema = null; this.HarmonicBehavior = new HarmonicBehavior(); this.BindingToTonic = new BindingBehavior(); this.BindingToModality = new BindingBehavior(); } /// /// Initializes a new instance of the HarmonicStructure class. /// /// The given system. /// Structural code. public HarmonicStructure(GeneralSystem givenSystem, string structuralCode) : base(givenSystem, structuralCode) { Contract.Requires(givenSystem != null); this.rootElement = -1; this.principalElement = -1; this.toneSchema = null; this.HarmonicBehavior = new HarmonicBehavior(); this.BindingToTonic = new BindingBehavior(); this.BindingToModality = new BindingBehavior(); } /// /// Initializes a new instance of the HarmonicStructure class. /// /// The given system. /// Number of structure. public HarmonicStructure(GeneralSystem givenSystem, long number) : base(givenSystem, number) { Contract.Requires(givenSystem != null); this.rootElement = -1; this.principalElement = -1; this.toneSchema = null; this.HarmonicBehavior = new HarmonicBehavior(); this.BindingToTonic = new BindingBehavior(); this.BindingToModality = new BindingBehavior(); this.DetermineLevel(); } /// /// Initializes a new instance of the class. /// /// The given system. /// The number. public HarmonicStructure(GeneralSystem givenSystem, decimal number) : base(givenSystem, (long)number) { Contract.Requires(givenSystem != null); this.rootElement = -1; this.principalElement = -1; this.toneSchema = null; this.HarmonicBehavior = new HarmonicBehavior(); this.BindingToTonic = new BindingBehavior(); this.BindingToModality = new BindingBehavior(); this.DetermineLevel(); } /// /// Initializes a new instance of the HarmonicStructure class. Serializable. /// /// Harmonic order. /// Melodic tones. public HarmonicStructure(byte harmonicOrder, Collection melodicTones) : base(HarmonicSystem.GetHarmonicSystem(harmonicOrder), (string)null) { Contract.Requires(melodicTones != null); this.HarmonicBehavior = new HarmonicBehavior(); this.BindingToTonic = new BindingBehavior(); this.BindingToModality = new BindingBehavior(); //// if (melodicTones == null) { return; } melodicTones.ForAll(mt => this.On(mt.Pitch.Element)); this.DetermineLevel(); this.ComputeVariance(); this.ComputeBalance(); } /// /// Initializes a new instance of the HarmonicStructure class. /// /// The given system. /// Bit array. public HarmonicStructure(GeneralSystem givenSystem, BitArray givenBitArray) : base(givenSystem, givenBitArray) { Contract.Requires(givenSystem != null); this.HarmonicBehavior = new HarmonicBehavior(); this.BindingToTonic = new BindingBehavior(); this.BindingToModality = new BindingBehavior(); } /// Initializes a new instance of the HarmonicStructure class. /// Thrown when a method Contract has been broken. /// Binary structure. public HarmonicStructure(BinaryStructure structure) : base(structure) { Contract.Requires(structure != null); this.HarmonicBehavior = new HarmonicBehavior(); this.BindingToTonic = new BindingBehavior(); this.BindingToModality = new BindingBehavior(); } /// Initializes a new instance of the HarmonicStructure class. /// The given system. /// The mark harmony. public HarmonicStructure(GeneralSystem givenSystem, XElement markHarmony) : base(givenSystem, (string)null) { string code = XmlSupport.ReadStringAttribute(markHarmony.Attribute("Code")); this.SetStructuralCode(code); this.DetermineLevel(); } #endregion #region Properties - Xml /// Gets Xml representation. /// Property description. public XElement GetXElement { get { var xe = new XElement( "Structure", new XAttribute("Shortcut", this.Shortcut ?? string.Empty), new XAttribute("Tones", this.ToneSchema ?? string.Empty), new XAttribute("Code", this.GetStructuralCode), new XAttribute("Start", this.BitFrom), new XAttribute("Length", this.Length)); return xe; } } /// /// Gets the get x element2. /// /// /// The get x element2. /// public XElement GetXElement2 { get { long classNumber = BinaryNumber.DetermineClassNumber(this.GSystem.Order, this.Number); var xe = new XElement( "Structure", new XAttribute("Level", this.Level), new XAttribute("Number", this.Number), new XAttribute("ClassNumber", classNumber), new XAttribute("Tones", this.ToneSchema ?? string.Empty), new XAttribute("Code", this.GetStructuralCode), new XElement( "Chord", new XAttribute("Root", this.Root), new XAttribute("Shortcut", this.Shortcut ?? string.Empty), new XAttribute("Consonance", Math.Round(this.HarmonicBehavior.Consonance, 0)), new XAttribute("Names", ChordNames(classNumber))), new XElement( "Modality", new XAttribute("Base", this.Root), new XAttribute("Names", ModalityNames(classNumber)))); return xe; } } #endregion #region Properties - Behavior /// /// Gets or sets the harmonic behavior. /// /// /// The harmonic behavior. /// public HarmonicBehavior HarmonicBehavior { get; set; } /// /// Gets or sets the binding from previous. /// /// /// The binding from previous. /// public BindingBehavior BindingFromPrevious { get; set; } /// /// Gets or sets the binding to tonic. /// /// /// The binding to tonic. /// public BindingBehavior BindingToTonic { get; set; } /// /// Gets or sets the binding to modality. /// /// /// The binding to modality. /// public BindingBehavior BindingToModality { get; set; } #endregion #region Interface - simple properties /// Gets or sets the string of musical symbols. /// Property description. [XmlAttribute] public string ToneSchema { get => this.toneSchema ?? (this.toneSchema = this.SchemaOfTones()); set => this.toneSchema = value; } /// /// Gets or sets the formal energy. /// /// /// The formal energy. /// public HarmonicBehavior FormalEnergy { get; set; } /// Gets the root tone. /// Property description. public string Root => ((HarmonicSystem)this.GSystem).Symbol(this.RootElement, true); /// Gets the principal tone. /// Property description. public string Principal => ((HarmonicSystem)this.GSystem).Symbol(this.PrincipalElement, true); #endregion #region Interface - object properties /// Gets harmonic system. /// Property description. [XmlIgnore] public HarmonicSystem HarmonicSystem => (HarmonicSystem)this.GSystem; /// Gets or sets harmonic modality. /// Property description. [XmlIgnore] public HarmonicModality HarmonicModality { get => (HarmonicModality)this.Modality; set { this.Modality = value; if (this.Modality != null) { this.DetermineBehaviorInModality(); } } } /// Gets or sets the previous structure. /// Property description. public HarmonicStructure PreviousStruct { get; set; } /// /// Gets or sets shortcut of harmonic structure. /// /// /// Property description. /// [XmlIgnore] public string Shortcut { get { if (this.shortcut != null) { return this.shortcut; } else { return this.ToneSchema; } } set => this.shortcut = value; } //// string ts = this.ToneSchema; /// /// Gets or sets the start. /// /// /// The start. /// public byte BitFrom { get; set; } /// /// Gets or sets the length. /// /// /// The length. /// public byte Length { get; set; } /// /// Gets BitRange. /// /// General musical property. public BitRange BitRange { get { var range = new BitRange(this.Order, this.BitFrom, this.Length); return range; } } #endregion #region Interface - private properties /// Gets or sets the root element. /// Property description. private short RootElement { get { if (this.rootElement == -1) { this.DetermineRootElement(); } return this.rootElement; } set => this.rootElement = value; } /// Gets or sets the principal element. /// Property description. private short PrincipalElement { get { if (this.principalElement == -1) { this.DeterminePrincipalElement(); } return this.principalElement; } set => this.principalElement = value; } #endregion #region Static factory methods /// /// Get new harmonic structure. /// /// The given system. /// Structural number. /// Returns value. public static HarmonicStructure GetNewHarmonicStructure(GeneralSystem givenSystem, long number) { Contract.Requires(givenSystem != null); var hs = new HarmonicStructure(givenSystem, number); hs.DetermineBehavior(); hs.Shortcut = hs.ToneSchema; return hs; } /// /// Get new harmonic structure. /// /// The given system. /// Structural code. /// /// Returns value. /// public static HarmonicStructure GetNewHarmonicStructure(GeneralSystem givenSystem, string structuralCode) { Contract.Requires(givenSystem != null); var hs = new HarmonicStructure(givenSystem, structuralCode); hs.DetermineBehavior(); hs.DetermineShortcut(); return hs; } /// /// Get NewHarmonicStruct. /// /// The given system. /// Structural Number. /// Transposition number. /// /// Returns value. /// public static HarmonicStructure GetNewHarmonicStruct(GeneralSystem givenSystem, long number, byte transposition) { Contract.Requires(givenSystem != null); var hs = new HarmonicStructure(givenSystem, BinaryNumber.Transposition(givenSystem, number, transposition)); hs.DetermineBehavior(); return hs; } /// /// To the binary. /// /// The numeral. /// /// Returns value. /// public static BitArray ToBinary(int numeral) { return new BitArray(new[] { numeral }); } /// /// To the numeral. /// /// The binary. /// /// Returns value. /// /// bit array /// Must be at most 32 bits long public static int ToNumeral(BitArray binary) { if (binary == null) { throw new ArgumentNullException(nameof(binary)); } if (binary.Length > 32) { throw new ArgumentException("must be at most 32 bits long"); } var result = new int[1]; binary.CopyTo(result, 0); return result[0]; } #endregion #region Public methods /// Makes a deep copy of the HarmonicStructure object. /// Returns object. public override object Clone() { var newStruct = GetNewHarmonicStructure(this.GSystem, this.GetStructuralCode); newStruct.Shortcut = this.Shortcut; newStruct.RootElement = this.RootElement; newStruct.PrincipalElement = this.PrincipalElement; return newStruct; } /// Evaluate properties of the structure. public override void DetermineBehavior() { this.ComputeVariance(); this.ComputeBalance(); var fs = new HarmonicStateFormal((HarmonicSystem)this.GSystem, this); this.HarmonicBehavior.Continuity = fs.FormalContinuity; this.HarmonicBehavior.Impulse = fs.FormalImpulse; this.HarmonicBehavior.Consonance = fs.FormalConsonance; const float formalGenus = 0; this.HarmonicBehavior.Genus = formalGenus; } /// /// Writes the behavior to properties. /// public override void WriteBehaviorToProperties() { if (this.HarmonicBehavior != null) { this.Properties[GenProperty.InnerContinuity] = this.HarmonicBehavior.Continuity ?? 0; this.Properties[GenProperty.InnerImpulse] = this.HarmonicBehavior.Impulse ?? 0; this.Properties[GenProperty.Consonance] = this.HarmonicBehavior.Consonance; this.Properties[GenProperty.Genus] = this.HarmonicBehavior.Genus; } if (this.BindingToTonic != null) { this.Properties[GenProperty.TonicContinuity] = this.BindingToTonic.Continuity ?? 0; this.Properties[GenProperty.TonicImpulse] = this.BindingToTonic.Impulse ?? 0; } } /// /// Determines the shortcut. /// public void DetermineShortcut() { string sc = string.Empty; //// this.ToneSchema; long number = ToNumeral(this.BitArray); long classNumber = BinaryNumber.DetermineClassNumber(this.GSystem.Order, number); string rootSymbol = this.Root.ToUpper(CultureInfo.InvariantCulture); if (this.Level == 3) { switch (classNumber) { /* Determine Shortcut unused variants case 37: { //// Sixth sc = rootSymbol + "6"; break; } case 41: { //// Septime sc = rootSymbol + "7"; break; } case 69: { //// Septime sc = rootSymbol + "7"; break; } */ case 133: { //// Sus 2 sc = rootSymbol + "sus2"; break; } case 137: { //// Minor sc = rootSymbol + "mi"; break; } case 145: { //// Major sc = rootSymbol; break; } case 273: { //// Extended sc = rootSymbol + "5+"; break; } } } if (this.Level == 4) { switch (classNumber) { case 329: { //// Seventh sc = rootSymbol + "7"; break; } case 291: { //// Major Seventh sc = rootSymbol + "maj7"; break; } case 275: { //// Major Seventh sc = rootSymbol + "mi-maj7"; break; } case 585: { //// Diminished sc = rootSymbol + "dim"; break; } } } this.Shortcut = !string.IsNullOrEmpty(sc) ? sc : this.ToneSchema; } #endregion #region Comparison /// Support sorting according to level and ElementSchema. /// Object to be compared. /// Returns value. public override int CompareTo(object obj) { if (!(obj is HarmonicStructure hstruct)) { return 0; } if (this.Level < hstruct.Level) { return -1; } return this.Level > hstruct.Level ? 1 : string.Compare(hstruct.ElementSchema, this.ElementSchema, StringComparison.Ordinal); //// This kills the DataGrid //// throw new ArgumentException("Object is not a HarmonicStructure"); } /// Test of equality. /// Object to be compared. /// Returns value. public override bool Equals(object obj) { //// check null (this pointer is never null in C# methods) if (object.ReferenceEquals(obj, null)) { return false; } if (object.ReferenceEquals(this, obj)) { return true; } if (this.GetType() != obj.GetType()) { return false; } return this.CompareTo(obj) == 0; } /// Support of comparison. /// Returns value. public override int GetHashCode() { return this.Number.GetHashCode(); } #endregion #region Determination of properties /// /// Sets properties of the structure with regard to tonic. /// /// Harmonical tonic. public void DetermineBehaviorToTonic(BinarySchema tonic) { if (tonic == null) { return; } var harmonicSystem = (HarmonicSystem)this.GSystem; var harRelation = new HarmonicRelation(harmonicSystem, this, tonic); var tcontinuity = harRelation.MeanValueOfProperty(GenProperty.InnerContinuity, false, true); var timpulse = harRelation.MeanValueOfProperty(GenProperty.InnerImpulse, false, true); this.BindingToTonic.Continuity = tcontinuity; this.BindingToTonic.Impulse = timpulse; } // Sets property of variability. // public void DetermineVariabilityInStream(HarFlow hStream) { // float variability = hStream.VariabilityForHarmonicStructure(this); // Properties[GenProperty.HarmonicVariability] = variability; // add with repetition // } #endregion #region Static characteristics /// Returns root values of the given element in the structure. /// Requested element. /// Returns value. public float RootValueOfElement(byte element) { var values = HarmonicStateFormal.RootValues(this); if (values != null && element < values.Count) { return values[element]; } return 0; } /// Returns principal value of the given element in the structure. /// Requested element. /// Returns value. public float PrincipalValueOfElement(byte element) { var values = HarmonicStateFormal.PrincipalValues(this); if (values != null && element < values.Count) { return values[element]; } return 0; } #endregion #region String representation /// /// Symbols at place. /// /// The given place. /// Returns value. public string SymbolAtPlace(short givenPlace) { var c = this.HarmonicSystem.Symbol(givenPlace, true); return c; } /// /// Returns symbols for given level. /// /// Given level. /// Returns value. public string SymbolAtLevel(short givenLevel) { var p = this.RealPlaceAtLevel(givenLevel); var c = this.SymbolAtPlace(p); return c; } /// /// Makes tone representation of the structure. /// /// /// Returns value. /// public string SchemaOfTones() { if (this.Level <= 0) { return string.Empty; } var str = new StringBuilder(); if (this.Modality is HarmonicModality modality) { var lastL = (byte)(this.Level - 1); string s; for (byte level = 0; level < lastL; level++) { s = modality.SymbolAtPlace(this.PlaceAtLevel(level)); str.Append(s); str.Append("-"); } s = modality.SymbolAtPlace(this.PlaceAtLevel(lastL)); str.Append(s); } else { var lastL = (byte)(this.Level - 1); string s; for (byte level = 0; level < lastL; level++) { s = this.SymbolAtLevel(level); //// this.PlaceAtLevel str.Append(s); //// str.Append(" "); } s = this.SymbolAtLevel(lastL); //// this.PlaceAtLevel str.Append(s); } return str.ToString().Trim(); } /// String representation of the object. /// Returns value. public override string ToString() { var s = new StringBuilder(); s.Append(base.ToString()); s.Append(this.ToneSchema); if (this.HarmonicModality != null) { s.Append(string.Format(CultureInfo.InvariantCulture, "\t (M:{0})\n", this.HarmonicModality.ToneSchema)); } //// s.Append(this.StringOfProperties()); //// [s appendFormat:@"C%7.2f I%7.2f s%7.2f G%1d", [this.continuity] floatValue], [this.impulse] floatValue], [this.sonance] floatValue], [this.genus] intValue]]; //// [s appendFormat:@"(%2s,%2s)", [[mxHSystem symbolAtIndex: this.rootElement]] cString], [[mxHSystem symbolAtIndex: this.principalElement]] cString]]; return s.ToString(); } #endregion #region Public behavior /// Sets previous harmonic structure and Compute corresponding properties. /// Harmonic structure. public void SetPreviousStruct(HarmonicStructure structure) { Contract.Requires(structure != null); this.PreviousStruct = structure; this.DetermineBehaviorFromPreviousStruct(); } /// Sets properties of the structure with regard to modality. public void DetermineBehaviorInModality() { Contract.Requires(this.HarmonicModality != null); const byte sonanceFactorToTonicity = 5; var harmonicSystem = (HarmonicSystem)this.GSystem; var harRelation = new HarmonicRelation(harmonicSystem, this.HarmonicModality, this); var continuity = harRelation.MeanValueOfProperty(GenProperty.InnerContinuity, true, true); var impulse = harRelation.MeanValueOfProperty(GenProperty.InnerImpulse, false, true); var potential = harRelation.MeanValueOfProperty(GenProperty.FormalPotentialInfluence, true, true); //// var mpotential2 = this.PotentialInModality(); //// var mpotential3 = this.Potential; var formalConsonance = this.Properties.ContainsKey(GenProperty.Consonance) ? this.Properties[GenProperty.Consonance] : 0; var mtonicity = potential + (formalConsonance / sonanceFactorToTonicity); this.Properties[GenProperty.ModalContinuity] = continuity; this.Properties[GenProperty.ModalImpulse] = impulse; this.Properties[GenProperty.Potential] = potential; this.Properties[GenProperty.Tonicity] = mtonicity; this.HarmonicBehavior.Potential = potential; } #endregion #region Private static /// /// Chords the names. /// /// The class number. /// /// Returns value. /// private static string ChordNames(long classNumber) { string s = string.Empty; switch (classNumber) { case 1: s = @"Unison"; break; case 3: s = @"Semitone"; break; case 5: s = @"Whole-tone"; break; case 9: s = @"Minor Third"; break; case 17: s = @"Major Third"; break; case 33: s = @"Perfect Fourth"; break; case 37: s = @"Incomplete Minor-seventh Chord"; break; case 41: s = @"Incomplete Dominant-seventh Chord.2"; break; case 65: s = @"Tritone"; break; case 67: s = @"Rite chord.2, Tritone-fourth.1"; break; case 69: s = @"Incomplete Dominant-seventh Chord.1"; break; case 73: s = @"Diminished Chord"; break; case 81: s = @"Incomplete Half-dim-seventh Chord"; break; case 97: s = @"Rite chord.1, Tritone-fourth.2"; break; case 145: s = @"Major Chord"; break; case 273: s = @"Augmented Chord"; break; case 725: s = @"Dominant-11th"; break; case 283: s = @"Minor-major Ninth Chord"; break; case 291: s = @"Major-seventh Chord"; break; case 293: s = @"Half-diminished Seventh Chord"; break; case 297: s = @"Minor-seventh Chord Raga Bhavani"; break; case 299: s = @"Major-Ninth Chord"; break; case 301: s = @"Diminished-major Ninth Chord"; break; case 307: s = @"Major-augmented Ninth Chord"; break; case 309: s = @"Diminished-augmented Ninth Chord"; break; case 325: s = @"French-sixth Chord"; break; case 329: s = @"Dominant-seventh/German-sixth Chord"; break; case 345: s = @"Augmented-diminished Ninth Chord"; break; case 361: s = @"Minor-diminished Ninth Chord"; break; case 409: s = @"Augmented-minor Chord"; break; case 425: s = @"Minor Ninth Chord"; break; case 585: s = @"Diminished-seventh Chord"; break; case 587: s = @"Diminished Minor-Ninth Chord"; break; case 619: s = @"Double-Phrygian Hexatonic/chord"; break; case 621: s = @"Pyramid Hexatonic/chord"; break; case 845: s = @"Petrushka chord"; break; case 877: s = @"Petrushka chord"; break; } return s; } /// /// Modalities the names. /// /// The class number. /// /// Returns value. /// private static string ModalityNames(long classNumber) { string s = string.Empty; switch (classNumber) { case 5: s = @"Warao ditonic (South America)"; break; case 7: s = @"Bach/Chromatic Trimirror"; break; case 11: s = @"Phrygian Trichord"; break; case 13: s = @"Minor Trichord"; break; case 15: s = @"BACH/Chromatic Tetramirror"; break; case 19: s = @"Major-minor Trichord.1"; break; case 21: s = @"Whole-tone Trichord"; break; case 23: s = @"Major-second Tetracluster.2"; break; case 25: s = @"Major-minor Trichord.2"; break; case 27: s = @"Alternating Tetramirror"; break; case 29: s = @"Major-second Tetracluster.1"; break; case 31: s = @"Chromatic Pentamirror"; break; case 33: s = @"Honchoshi,Niagari (Japan)"; break; case 37: s = @"Ute tritonic"; break; case 39: s = @"Minor-Third Tetracluster.2"; break; case 43: s = @"Dorian Tetrachord, Phrygian Tetrachord"; break; case 45: s = @"Phrygian Tetrachord, Minor Tetramirror"; break; case 47: s = @"Major-second Pentacluster.2"; break; case 51: s = @"Chromatic Mezotetrachord, Arabian Tetramirror"; break; case 53: s = @"Lydian Tetrachord, Major Tetrachord Warao tetratonic: South America"; break; case 55: s = @"Minor-second Major Pentachord"; break; case 57: s = @"Minor-Third Tetracluster.1"; break; case 59: s = @"Spanish Pentacluster"; break; case 61: s = @"Major-second Pentacluster.1"; break; case 63: s = @"Chromatic Hexamirror"; break; case 71: s = @"Major-Third Tetracluster.2"; break; case 75: s = @"Minor-second Diminished Tetrachord"; break; case 77: s = @"Harmonic-minor Tetrachord"; break; case 79: s = @"Blues Pentacluster"; break; case 83: s = @"All-interval Tetrachord.1"; break; case 85: s = @"Whole-tone Tetramirror"; break; case 87: s = @"Tritone-Expanding Pentachord"; break; case 89: s = @"Major-third Diminished Tetrachord"; break; case 91: s = @"Alternating Pentachord.1"; break; case 93: s = @"Tritone-Symmetric Pentamirror"; break; case 99: s = @"Double Fourth Tetramirror"; break; case 101: s = @"All-interval Tetrachord.2"; break; case 103: s = @"Oriental Pentacluster.1"; break; case 105: s = @"Perfect-fourth Diminished Tetrachord"; break; case 107: s = @"Locrian Pentamirror"; break; case 109: s = @"Alternating Pentachord.2"; break; case 113: s = @"Major-Third Tetracluster.1"; break; case 115: s = @"Oriental Pentacluster.2"; break; case 117: s = @"Tritone-Contracting Pentachord"; break; case 121: s = @"Minor-third Pentacluster"; break; case 127: s = @"Chromatic Heptamirror"; break; case 133: s = @"Quartal Trichord, Warao tritonic (South America), Sansagari (Japan)"; break; case 409: s = @"Lebanese Pentachord"; break; case 135: s = @"Perfect Fourth Tetramirror"; break; case 137: s = @"Minor Chord Peruvian tritonic 2"; break; case 139: s = @"All-interval Tetrachord.3"; break; case 141: s = @"Major-second Minor Tetrachord"; break; case 143: s = @"Major-third Pentacluster.2"; break; case 147: s = @"Major-diminished Tetrachord"; break; case 149: s = @"Eskimo tetratonic (Alaska), Major-second Major Tetrachord"; break; case 151: s = @"Major-seventh Pentacluster.2"; break; case 153: s = @"Major-minor Tetramirror"; break; case 155: s = @"Major-minor-dim Pentachord.1"; break; case 157: s = @"Center-cluster Pentachord.1"; break; case 163: s = @"Minor-second Quartal Tetrachord"; break; case 165: s = @"Quartal Tetramirror, Genus primum"; break; case 167: s = @"Double-seconds Triple-fourth Pentachord.1"; break; case 169: s = @"Perfect-fourth Minor Tetrachord"; break; case 171: s = @"Phrygian Pentachord"; break; case 173: s = @"Dorian/Minor Pentachord, Jewish"; break; case 177: s = @"Perfect-fourth Major Tetrachord"; break; case 179: s = @"Gypsy/semiditonic Pentachord.1"; break; case 181: s = @"Major/Ionic Pentachord"; break; case 185: s = @"Center-cluster Pentachord.2"; break; case 195: s = @"Messiaen's truncated 5, Lendvai's, Double Tritone Tetramirror"; break; case 197: s = @"Tritone Quartal Tetrachord"; break; case 199: s = @"Double Pentacluster1"; break; case 201: s = @"Minor-diminished Tetrachord"; break; case 203: s = @"Javanese Pentachord"; break; case 205: s = @"Gypsy/semiditonic Pentachord.2"; break; case 209: s = @"All-interval Tetrachord.4"; break; case 211: s = @"Balinese Pentachord"; break; case 213: s = @"Lydian Pentachord"; break; case 217: s = @"Major-minor-dim Pentachord.2"; break; case 219: s = @"Alternating Hexamirror"; break; case 227: s = @"Double Pentacluster.2"; break; case 229: s = @"Double-seconds Triple-fourth Pentachord.2"; break; case 231: s = @"Double-cluster Hexamirror"; break; case 233: s = @"Major-seventh Pentacluster.1"; break; case 241: s = @"Major-third Pentacluster.2"; break; case 255: s = @"Chromatic Octamirror"; break; case 275: s = @"Minor-augmented Tetrachord"; break; case 279: s = @"Augmented Pentacluster.1"; break; case 281: s = @"Augmented-major Tetrachord"; break; case 285: s = @"Augmented Pentacluster.2"; break; case 295: s = @"Diminished Pentacluster.1"; break; case 307: s = @"Syrian pentatonic"; break; case 313: s = @"Center-cluster Pentamirror"; break; case 315: s = @"Indian Sharavati"; break; case 325: s = @"Messiaen's truncated 6"; break; case 327: s = @"Bardos's, Asymmetric Pentamirror, Indian Gauri"; break; case 331: s = @"Kumoi Pentachord.2, Mixolydian Pentatonic"; break; case 333: s = @"Augmented-sixth Pentachord.1, Indian Marga Hindola"; break; case 339: s = @"Enigmatic Pentachord.1, Indian Nata"; break; case 341: s = @"Whole-tone Pentamirror"; break; case 343: s = @"Arabian Major Locrian"; break; case 347: s = @"Indian Sharasvati"; break; case 355: s = @"Balinese Pelog Pentatonic, Korean"; break; case 357: s = @"Javan Pentatonic, Augmented-sixth Pentachord.2, Indian Hindola"; break; case 363: s = @"Locrian Hexachord"; break; case 365: s = @"Super-Locrian Hexamirror"; break; case 371: s = @"Indian Malarani"; break; case 397: s = @"Indian-Japan Pentatonic"; break; case 403: s = @"Persian Pentamirror"; break; case 405: s = @"Enigmatic Pentachord.2, Altered Pentatonic"; break; case 407: s = @"Indian Vijayasri"; break; case 411: s = @"Indian Paraju"; break; case 413: s = @"Megha or Cloud"; break; case 421: s = @"Korean, Kumoi Pentachord.1"; break; case 427: s = @"Phrygian Hexamirror"; break; case 429: s = @"Minor Hexachord"; break; case 435: s = @"Gypsy hexatonic"; break; case 437: s = @"Hawaiian, Melodic-minor Hexachord"; break; case 455: s = @"Messiaen's 5"; break; case 457: s = @"Diminished Pentacluster.2"; break; case 511: s = @"Chromatic Nonamirror"; break; case 589: s = @"Flat-Ninth Pentachord"; break; case 595: s = @"Neapolitan Pentachord.1"; break; case 597: s = @"Major-minor, Prometheus Pentamirror, Korean"; break; case 603: s = @"Indian Ghantana"; break; case 613: s = @"Neapolitan Pentachord.2, Scriabin"; break; case 615: s = @"Schoenberg Anagram Hexachord"; break; case 623: s = @"Debussy's Heptatonic"; break; case 661: s = @"Natural/Genuine/Black Key Pentatonic, Slendro, Kausika, Mehga"; break; case 667: s = @"Indian Dipaka, Prometheus Neapolitan"; break; case 669: s = @"Blues scale I, Indian Marva"; break; case 683: s = @"Scriabin's Mystic, Prometheus Hexachord, Eskimo (Alaska)"; break; case 685: s = @"Dorian Hexachord"; break; case 693: s = @"Guidon/Arezzo/Natural/Genuine/Persian Hexachord"; break; case 715: s = @"Messiaen's truncated 2, Minor-bitonal Hexachord"; break; case 725: s = @"Natural/Genuine/Lydian Hexachord, Ancient Chinese"; break; case 727: s = @"Bluesy R&R"; break; case 731: s = @"Gypsy, Moravian Pistalkova (Whistle), Alternating Heptachord.1, Hungarian Major"; break; case 735: s = @"Blues Octatonic"; break; case 743: s = @"Indian, Chromatic inverse"; break; case 757: s = @"Tritone Major Heptachord"; break; case 819: s = @"Augmented, Messiaen's truncated 3, Lendvai's, Genus tertium"; break; case 827: s = @"Gipsy Hexatonic"; break; case 829: s = @"Verdi's Enigmatic"; break; case 845: s = @"Messiaen's truncated 2, Major-bitonal Hexachord"; break; case 847: s = @"Indian Shyamalam"; break; case 853: s = @"Harmonic Hexachord, Augmented-11th, Indian Sviraga"; break; case 855: s = @"Neapolitan"; break; case 859: s = @"Harmonic Minor, Spanish Gypsy"; break; case 861: s = @"Indian Narmada"; break; case 863: s = @"Indian Cintamani"; break; case 871: s = @"Persian, Gypsy, Hungarian, Double Harmonic, Indian Bhairava, Turkish, Oriental"; break; case 875: s = @"Harmonic Major"; break; case 877: s = @"Diminished, Alternating Heptachord.2"; break; case 925: s = @"Greek Chromatic, Indian"; break; case 949: s = @"Modified Blues"; break; case 955: s = @"Indian Saurastra"; break; case 975: s = @"Messiaen's 4"; break; case 981: s = @"Enigmatic Heptatonic, Verdi's Enigmatic"; break; case 983: s = @"Verdi's Enigmatic, Free-constructed"; break; case 987: s = @"Algerian"; break; case 1013: s = @"Blues Octatonic"; break; case 1023: s = @"Chromatic Decamirror"; break; case 1365: s = @"Whole-tone, Messiaen's mode 1, Anhemitonic Hexatonic"; break; case 1367: s = @"Neapolitan, Leading Whole-tone, Combined"; break; case 1371: s = @"Jazz Minor, Bartok's, Acoustic, Plane-altered, Moravian Podhalska"; break; case 1387: s = @"Natural/Genuine, Medieval, Greek"; break; case 1403: s = @"Spanish Octatonic, Espla's scale, Jewish"; break; case 1455: s = @"Greek Complete, Egyptian, Blues"; break; case 1463: s = @"Arabic Zirafkend"; break; case 1467: s = @"Spanish, Major-Minor, Blues"; break; case 1471: s = @"Nonatonic Blues"; break; case 1495: s = @"Messiaen's 6"; break; case 1519: s = @"Major-minor Nonatonic"; break; case 1755: s = @"Diminished, Messiaen's 2, Lendvai's, Half-Whole step"; break; case 1775: s = @"Moorish Phrygian"; break; case 1783: s = @"Youlan scale (China), Diminished Nonachord"; break; case 1791: s = @"Indian Sindhi-Bhairavi"; break; case 1911: s = @"Messiaen's 3, Tsjerepnin, Genus chromaticum"; break; case 1983: s = @"Major-minor mixed, Minor Pentatonic with leading tones"; break; case 2015: s = @"Messiaen's 7, Symmetrical Decatonic"; break; case 2047: s = @"Chromatic Undecamirror"; break; case 4095: s = @"Twelve-tone Chromatic, Dodecamirror"; break; } return s; } #endregion #region Private methods /// Returns potential values of elements in the structure. /// Returns value. private Collection PotentialValues() { Contract.Requires(this.HarmonicModality != null); //// HarmonicSystem hS = (HarmonicSystem)this.GSystem; var potentialValues = new Collection(); foreach (var p in this.Places.Select(e => this.HarmonicModality.PotentialOfElement(e))) { potentialValues.Add(p); } return potentialValues; } /// Sets properties of the structure with regard to previous structure. private void DetermineBehaviorFromPreviousStruct() { Contract.Requires(this.PreviousStruct != null); var harmonicSystem = (HarmonicSystem)this.GSystem; var harRelation = new HarmonicRelation(harmonicSystem, this.PreviousStruct, this); var continuity = harRelation.MeanValueOfProperty(GenProperty.InnerContinuity, false, true); var impulse = harRelation.MeanValueOfProperty(GenProperty.InnerImpulse, false, true); this.Properties[GenProperty.RelatedContinuity] = continuity; //// add with repetition this.Properties[GenProperty.RelatedImpulse] = impulse; //// add with repetition } /// Sets principal element. private void DeterminePrincipalElement() { var va = HarmonicStateFormal.PrincipalValues(this); float maxValue = -1000; short maxElement = -1; byte e = 0; if (va != null) { foreach (var v in va) { if (this.IsOn(e) && (v > maxValue)) { maxValue = v; maxElement = e; } e++; } } this.principalElement = maxElement; //// indexOfObject MAX([self PrincipalValues]); } /// Sets root element. private void DetermineRootElement() { var va = HarmonicStateFormal.RootValues(this); float maxValue = -1000; short maxElement = -1; byte e = 0; if (va != null) { foreach (var v in va) { if (this.IsOn(e) && (v > maxValue)) { maxValue = v; maxElement = e; } e++; } } this.rootElement = maxElement; } #endregion #region Relation to modality /// Returns total potential of the structure in modality. /// Returns value. private float PotentialInModality() { Contract.Requires(this.HarmonicModality != null); var values = this.PotentialValues(); var sum = values?.Sum() ?? 0; return sum; } #endregion } }